try:
    fname = input('Please enter the file name, default(mbox-short.txt)\n')
    if fname == '':
        fname = 'mbox-short.txt'
    fhand = open(fname, 'r')
except Exception as e:
    print('can\'t open the file -', fname)
    exit()

time_counter = {}
for line in fhand:
    if not line.startswith('From '):
        continue

    words = line.split()
    if len(words) < 6:
        continue
    time = words[5]
    hour, _, _ = time.split(':')
    time_counter[hour] = time_counter.get(hour, 0) + 1

# print(time_counter)
hours = []
for hour in time_counter:
    hours.append(hour)

hours.sort()
for hour in hours:
    print(hour, time_counter[hour])
